/-boot
/-docs
/-editor
/-files
/-files-old
/-imports
/-layout
/-shell
/-storage
/-tests
/-typings
Dom.ts
TypeScriptService.ts
functions.ts
ko.ts
nteapo.html
persistence.api.ts
persistence.ts
shell.ts
teapo.html
teapo.ts
tmp.ts
try.html
try.js
xxxxxxxxxx
 
1
/// <reference path='typings/typescriptServices.d.ts' />
2
/// <reference path='typings/codemirror.d.ts' />
3
​
4
module teapo {
5
​
6
  /**
7
   * Pubic API exposing access to TypeScript language  services
8
   * (see its service property)
9
   * and handling the interfaces TypeScript requires
10
   * to access to the source code and the changes.
11
   */
12
  export class TypeScriptService {
13
​
14
    /** Set of booleans for each log severity level. */
15
    logLevels = {
16
      information: false,
17
      debug: false,
18
      warning: true,
19
      error: true,
20
      fatal: true
21
    };
22
​
23
    /** TypeScript custom settings. */
24
    compilationSettings: ts.CompilerOptions = {};
25
​
26
    registry: ts.DocumentRegistry = null;
27
​
28
    /** Main public API of TypeScript compiler/parser engine. */
29
    service: ts.LanguageService;
30
​
31
    /** Files added to the compiler/parser scope, by full path. */
32
    scripts: { [fullPath: string]: TypeScriptService.Script; } = {};
33
​
34
    log: { logLevel: string; text: string; }[] = null;
35
  
36
    private _logLevel: string = null;
37
​
38
​
39
    constructor() {
40
      this.registry = ts.createDocumentRegistry();
41
      this.service = ts.createLanguageService(this._createLanguageServiceHost(), this.registry);
42
    }
43
​
44
    /**
45
     * The main API required by TypeScript for talking to the host environment. */
46
    private _createLanguageServiceHost(): ts.LanguageServiceHost {
47
​
48
      return {
49
        getCurrentDirectory: () => '/',
50
        getDefaultLibFilename: () => '#lib.d.ts',
51
        getCancellationToken: () => null,
52
        getCompilationSettings: () => this.compilationSettings,
53
        getScriptFileNames: () => {
54
          var result = Object.keys(this.scripts).filter(k => this.scripts.hasOwnProperty(k)).sort();
55
          //console.log('...getScriptFileNames():',result);
56
          return result;
57
        },
58
        getScriptVersion: (fileName: string) => {
59
          var script = this.scripts[fileName];
60
          if (script.changes)
61
            return (script.changes().length+1)+'';
35:37